package com.example.hrandroidapp.preferences;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.hrandroidapp.domain.ServerPO;

public class CurrentServerPreference {

	private static final String PARAM_SVR_NAME = "serverName";
	private static final String PARAM_SVR_IP = "serverIP";
	
	private static final String CURRENT_SVR_FILE_NAME = "currServer";
	
	public CurrentServerPreference() {}

	public static ServerPO getCurrentServer(Context context) {
        ServerPO server = new ServerPO();
        SharedPreferences prefs = context.getSharedPreferences(CURRENT_SVR_FILE_NAME, Context.MODE_PRIVATE);
        server.setSvrName(prefs.getString(PARAM_SVR_NAME, null));
        server.setSvrIP(prefs.getString(PARAM_SVR_IP, null));
       
        return server;
    }
	 
    public static void updateCurrentServer(Context context, ServerPO server) {
        SharedPreferences prefs = context.getSharedPreferences(CURRENT_SVR_FILE_NAME, Context.MODE_PRIVATE);
        prefs.edit().putString(PARAM_SVR_NAME, server.getSvrName()).commit();
        prefs.edit().putString(PARAM_SVR_IP, server.getSvrIP()).commit();
    }
    
    public static void clearCurrentServer(Context context) {
    	SharedPreferences settings = context.getSharedPreferences(CURRENT_SVR_FILE_NAME, Context.MODE_PRIVATE);
    	settings.edit().remove(PARAM_SVR_NAME).commit();
    	settings.edit().remove(PARAM_SVR_IP).commit();
    }

}
